<?php
class comment_model_recive extends Model {
	public function __construct(){
		parent::__construct();
		$this->table = 'app_com_recive';
	}
	
	//更新 未读信息 //发帖 //回帖
	public function update_recive($uid){
		$num = count($uid);
		for($i=0;$i<$num;$i++){
			$sql = "select unread from ".$this->table." where uid=&uid";
			$params = array('uid'=>$uid[$i]['uid']);
			$result = $this->db->fetchRow($sql, $params);
			if($result){
				$sql = "update ".$this->table." set unread=unread+1  where uid=&uid";
				$params = array('uid'=>$uid[$i]['uid']);
				return $this->db->query($sql, $params);
			}else{
				$arguments['uid'] = $uid[$i]['uid'];
				$arguments['unread'] = 1;
		        $this->db->insert($this->table, $arguments);
			}
		}
		
	}
	//清除 未读纪录
	public function clear_recive($uid){
				$sql = "update ".$this->table." set unread=0  where uid=&uid";
				$params = array('uid'=>$uid);
				return $this->db->query($sql, $params);
	}
	//得到 未读纪录
	public function get_recive($uid){
			$sql = "select * from ".$this->table." where uid=&uid";
			$params = array('uid'=>$uid);
			return $result = $this->db->fetchRow($sql, $params);
	}
	
}